import $ from "jquery";

const firefox = navigator.userAgent.indexOf('Firefox') != -1; 

//鼠标滚轮事件
const MouseWheel=(e,srcElementId)=>{
    e=e||window.event;
    const scrollLength=100;
    if(e&&e.srcElement&&e.srcElement.id&&e.srcElement.id==srcElementId){
        if(e.stopPropagation){
            e.stopPropagation();
          }else{
            e.cancelBubble=true;
          }
          
          if(e.preventDefault){
            e.preventDefault();
          }else{
            e.returnValue=false;
          }
      
          let borderDiv=$('#prj_board_container');
          if(firefox){
            if(e.detail<0){
                borderDiv.scrollLeft(borderDiv.scrollLeft()-scrollLength);
            }else{
                borderDiv.scrollLeft(borderDiv.scrollLeft()+scrollLength);
            }         
          }else{
            if(e.wheelDelta>0){
                borderDiv.scrollLeft(borderDiv.scrollLeft()-scrollLength);
            }else{
                borderDiv.scrollLeft(borderDiv.scrollLeft()+scrollLength);
            }
          }
    }
}

export const MouseWheelFun=(elementId,srcElementId)=>{
    var element =document.getElementById(elementId);
    firefox?element.addEventListener('DOMMouseScroll',e=>MouseWheel(e,srcElementId),false):(element.onmousewheel=e=>MouseWheel(e,srcElementId));
}